package com.zhaoyue.study.util;

import org.apache.commons.lang3.SerializationUtils;

import java.io.Serializable;

/**
 * @author zhaoyue
 * @description:
 * @create 2018-11-19 下午6:26
 **/
public class SerializationDemo implements Serializable,Cloneable{

    private String name;
    private int age;
    private User user;

    public static class User implements Serializable {
        private String id;
        private String userName;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static void main(String[] args) throws Exception{
        SerializationDemo s = new SerializationDemo();
        s.setAge(1);
        s.setName("zhaoyue");
        User user = new User();
        user.setUserName("aaa");
        s.setUser(user);

        SerializationDemo s1 = SerializationUtils.clone(s);
        //SerializationDemo s1 = (SerializationDemo)s.clone();
        System.out.println(s == s1);
        System.out.println(s.user == s1.user);
    }
}
